package com.alex.mda.jdbc.meta;

import java.math.BigDecimal;
import java.sql.Date;
import java.sql.Time;
import java.sql.Timestamp;
import java.sql.Types;
import java.util.HashMap;
import java.util.Map;

public class Column {

    private String name;

    private int sqlType;

    private String remarks;

    public Column(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getSqlType() {
        return sqlType;
    }

    public void setSqlType(int sqlType) {
        this.sqlType = sqlType;
    }

    public Class<?> getJavaType() {
        if (sqlType == 0) {
            return null;
        }
        return sql2JavaTypesMapping.get(sqlType);
    }

    public String getRemarks() {
        return remarks;
    }

    public void setRemarks(String remarks) {
        this.remarks = remarks;
    }

    private static Map<Integer, Class<?>> sql2JavaTypesMapping = new HashMap<Integer, Class<?>>();

    static {
        sql2JavaTypesMapping.put(Types.CHAR, String.class);
        sql2JavaTypesMapping.put(Types.VARCHAR, String.class);
        sql2JavaTypesMapping.put(Types.LONGVARCHAR, String.class);
        sql2JavaTypesMapping.put(Types.NUMERIC, BigDecimal.class);
        sql2JavaTypesMapping.put(Types.DECIMAL, BigDecimal.class);
        sql2JavaTypesMapping.put(Types.BIT, Boolean.class);
        sql2JavaTypesMapping.put(Types.TINYINT, Integer.class);
        sql2JavaTypesMapping.put(Types.SMALLINT, Integer.class);
        sql2JavaTypesMapping.put(Types.INTEGER, Integer.class);
        sql2JavaTypesMapping.put(Types.BIGINT, Long.class);
        sql2JavaTypesMapping.put(Types.REAL, Float.class);
        sql2JavaTypesMapping.put(Types.FLOAT, Double.class);
        sql2JavaTypesMapping.put(Types.DOUBLE, Double.class);
        sql2JavaTypesMapping.put(Types.BINARY, byte[].class);
        sql2JavaTypesMapping.put(Types.VARBINARY, byte[].class);
        sql2JavaTypesMapping.put(Types.LONGVARBINARY, byte[].class);
        sql2JavaTypesMapping.put(Types.DATE, Date.class);
        sql2JavaTypesMapping.put(Types.TIME, Time.class);
        sql2JavaTypesMapping.put(Types.TIMESTAMP, Timestamp.class);
    }

}
